package com.gqj.elec.controller;

import com.gqj.common.annotation.Log;
import com.gqj.common.core.controller.BaseController;
import com.gqj.common.core.domain.AjaxResult;
import com.gqj.common.core.page.TableDataInfo;
import com.gqj.common.enums.BusinessType;
import com.gqj.common.utils.poi.ExcelUtil;
import com.gqj.elec.domain.ElecMaterialRepair;
import com.gqj.elec.service.IElecMaterialRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物资检修Controller
 * 
 * @author lxq
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/elec/elecMaterialRepair")
public class ElecMaterialRepairController extends BaseController
{
    @Autowired
    private IElecMaterialRepairService elecMaterialRepairService;

    /**
     * 查询物资检修列表
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialRepair:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElecMaterialRepair elecMaterialRepair)
    {
        startPage();
        elecMaterialRepair.setDelFlag("0");
        List<ElecMaterialRepair> list = elecMaterialRepairService.selectElecMaterialRepairList(elecMaterialRepair);
        return getDataTable(list);
    }

    /**
     * 导出物资检修列表
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialRepair:export')")
    @Log(title = "物资检修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElecMaterialRepair elecMaterialRepair)
    {
        elecMaterialRepair.setDelFlag("0");
        List<ElecMaterialRepair> list = elecMaterialRepairService.selectElecMaterialRepairList(elecMaterialRepair);
        ExcelUtil<ElecMaterialRepair> util = new ExcelUtil<ElecMaterialRepair>(ElecMaterialRepair.class);
        util.exportExcel(response, list, "物资检修数据");
    }

    /**
     * 获取物资检修详细信息
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialRepair:query')")
    @GetMapping(value = "/{repairId}")
    public AjaxResult getInfo(@PathVariable("repairId") Long repairId)
    {
        return AjaxResult.success(elecMaterialRepairService.selectElecMaterialRepairByRepairId(repairId));
    }

    /**
     * 新增物资检修
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialRepair:add')")
    @Log(title = "物资检修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElecMaterialRepair elecMaterialRepair)
    {
        if (null == elecMaterialRepair.getElecMaterialList() || elecMaterialRepair.getElecMaterialList().size() <= 0) {
            return AjaxResult.error("工器具列表为空，不允许新增");
        }
        elecMaterialRepair.setCreateBy(getUsername());
        return toAjax(elecMaterialRepairService.insertElecMaterialRepair(elecMaterialRepair));
    }

    /**
     * 修改物资检修
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialRepair:edit')")
    @Log(title = "物资检修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElecMaterialRepair elecMaterialRepair)
    {
        if (null == elecMaterialRepair.getElecMaterialList() || elecMaterialRepair.getElecMaterialList().size() <= 0) {
            return AjaxResult.error("工器具列表为空，不允许修改");
        }
        elecMaterialRepair.setUpdateBy(getUsername());
        return toAjax(elecMaterialRepairService.updateElecMaterialRepair(elecMaterialRepair));
    }

    /**
     * 删除物资检修
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialRepair:remove')")
    @Log(title = "物资检修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repairIds}")
    public AjaxResult remove(@PathVariable Long[] repairIds)
    {
        return toAjax(elecMaterialRepairService.deleteElecMaterialRepairByRepairIds(repairIds));
    }
}
